%% This program plots the size and speed data;
% it does it for EXPERIMENT, not full data

%Don't forget to change the name of the folders to load acordingly to the
%type of experiments being analyzed; don't forget to change the title for
%the graphs
%do this for each graph

clear all
%% Load all datasets of the experiment

load ('/Users/anapereira/Dropbox/Matlab/data/sizeandspeedarray.mat');
load ('/Users/anapereira/Dropbox/Matlab/data/matlab data/RRF3_exp30_ZC2834_F1/RRF3_exp30_ZC2834_OP choice OP/RRF3_exp30_ZC2834_OP_to_OP_F1.mat');
load ('/Users/anapereira/Dropbox/Matlab/data/matlab data/RRF3_exp30_ZC2834_F1/RRF3_exp30_ZC2834_OP choice PA/RRF3_exp30_ZC2834_OP_to_PA_F1.mat');
load ('/Users/anapereira/Dropbox/Matlab/data/matlab data/RRF3_exp30_ZC2834_F1/RRF3_exp30_ZC2834_PA choice OP/RRF3_exp30_ZC2834_PA_to_OP_F1.mat');
load ('/Users/anapereira/Dropbox/Matlab/data/matlab data/RRF3_exp30_ZC2834_F1/RRF3_exp30_ZC2834_PA choice PA/RRF3_exp30_ZC2834_PA_to_PA_F1.mat');

dataOPOP = RRF3_exp30_ZC2834_OP_to_OP_F1; %change name
dataOPPA = RRF3_exp30_ZC2834_OP_to_PA_F1; %change name
dataPAOP = RRF3_exp30_ZC2834_PA_to_OP_F1; %change name
dataPAPA = RRF3_exp30_ZC2834_PA_to_PA_F1; %change name

exp = 'RRF3_Exp5_N2';
cond = 'OPvsPA F1';
sizeandspeedanalyzis {12,1,1} = exp;
sizeandspeedanalyzis {12,2,1} = cond;

%% Analyze for dataset OP to OP 

% Average speed
sujeitosOPOP = size (dataOPOP,1)-1;% because it is counting with the label row
sujeitosloopOPOP = sujeitosOPOP + 1;

averageindspeed = dataOPOP (2:sujeitosloopOPOP, 26); %extract average speed data - aritmetic 

averageindspeedvalues = zeros (sujeitosOPOP,1);
for i=1:sujeitosOPOP;
    aisvalues = averageindspeed {i,1};
    averageindspeedvalues(i) = aisvalues;
end

if sujeitosOPOP >= 3 % each individual comes with one value for reversals
[H, pValue1, W] = swtest(averageindspeedvalues, 0.05);%null hypothesis data comes from normal distribuition; if h=1 reject null hypothesis that data comes from a normal distribuition
elseif sujeitosOPOP ==2 
    pValue1 = NaN;
elseif sujeitosOPOP ==1 
    pValue1 = NaN;
elseif sujeitosOPOP ==0
    pValue1= NaN;
end
 
averagespeedall = mean (averageindspeedvalues);
desvpadraoavrspeedall = std (averageindspeedvalues);
semavrspeedall = desvpadraoavrspeedall./ (sqrt (sujeitosOPOP));
medianaavrspeedall = median (averageindspeedvalues);

sizeandspeedanalyzis {2,2,1} = averageindspeedvalues;
sizeandspeedanalyzis {3,2,1} = pValue1;
sizeandspeedanalyzis {4,2,1} = averagespeedall;
sizeandspeedanalyzis {5,2,1} = desvpadraoavrspeedall;
sizeandspeedanalyzis {6,2,1} = sujeitosOPOP;
sizeandspeedanalyzis {7,2,1} = semavrspeedall;
sizeandspeedanalyzis {8,2,1} = medianaavrspeedall;

% Speed range

indspeedrange = dataOPOP (2:sujeitosloopOPOP, 25); %extracts speed range for each animal

indspeedrangevalues = zeros (sujeitosOPOP,1);

for i=1:sujeitosOPOP;
    isrvalues = indspeedrange {i,1};
    indspeedrangevalues (i) = isrvalues;
end

if sujeitosOPOP >= 3 % each individual comes with one value for reversals
[H, pValue2, W] = swtest(indspeedrangevalues, 0.05);%null hypothesis data comes from normal distribuition; if h=1 reject null hypothesis that data comes from a normal distribuition
elseif sujeitosOPOP ==2 
    pValue2 = NaN;
elseif sujeitosOPOP ==1 
    pValue2 = NaN;
elseif sujeitosOPOP ==0
    pValue2= NaN;
end
 
rangespeedall = mean (indspeedrangevalues);
desvpadraorangespeedall = std (indspeedrangevalues);
semrangespeedall = desvpadraorangespeedall./ (sqrt (sujeitosOPOP));
medianarangespeedall = median (indspeedrangevalues);

sizeandspeedanalyzis {2,6,1} = indspeedrangevalues;
sizeandspeedanalyzis {3,6,1} = pValue2;
sizeandspeedanalyzis {4,6,1} = rangespeedall;
sizeandspeedanalyzis {5,6,1} = desvpadraorangespeedall;
sizeandspeedanalyzis {6,6,1} = sujeitosOPOP;
sizeandspeedanalyzis {7,6,1} = semrangespeedall;
sizeandspeedanalyzis {8,6,1} = medianarangespeedall;

% Size

indsize = dataOPOP (2:sujeitosloopOPOP, 13); %extracts size for each animal

indsizevalues = zeros (sujeitosOPOP,1);

for i=1:sujeitosOPOP;
    isizevalues = indsize {i,1};
    indsizevalues (i) = isizevalues;
end

if sujeitosOPOP >= 3 % each individual comes with one value for reversals
[H, pValue3, W] = swtest(indsizevalues, 0.05);%null hypothesis data comes from normal distribuition; if h=1 reject null hypothesis that data comes from a normal distribuition
elseif sujeitosOPOP ==2 
    pValue3 = NaN;
elseif sujeitosOPOP ==1 
    pValue3 = NaN;
elseif sujeitosOPOP ==0
    pValue3= NaN;
end
 
sizeall = mean (indsizevalues);
desvpadraosizeall = std (indsizevalues);
semsizeall = desvpadraosizeall./ (sqrt (sujeitosOPOP));
medianasizeall = median (indsizevalues);

sizeandspeedanalyzis {2,10,1} = indsizevalues;
sizeandspeedanalyzis {3,10,1} = pValue3;
sizeandspeedanalyzis {4,10,1} = sizeall;
sizeandspeedanalyzis {5,10,1} = desvpadraosizeall;
sizeandspeedanalyzis {6,10,1} = sujeitosOPOP;
sizeandspeedanalyzis {7,10,1} = semsizeall;
sizeandspeedanalyzis {8,10,1} = medianasizeall;

%time to arrive
averagetimetoarrive = dataOPOP (2:sujeitosloopOPOP, 12); %extract time to arrive

averagetimetoarrivevalues = zeros (sujeitosOPOP,1);
for i=1:sujeitosOPOP;
    attavalues = averagetimetoarrive {i,1};
    averagetimetoarrivevalues(i) = attavalues;
end

if sujeitosOPOP >= 3 % each individual comes with one value for reversals
[H, pValue4, W] = swtest(averagetimetoarrivevalues, 0.05);%null hypothesis data comes from normal distribuition; if h=1 reject null hypothesis that data comes from a normal distribuition
elseif sujeitosOPOP ==2 
    pValue4 = NaN;
elseif sujeitosOPOP ==1 
    pValue4 = NaN;
elseif sujeitosOPOP ==0
    pValue4= NaN;
end
 
averagetimetoarriveall = mean (averagetimetoarrivevalues);
desvpadraotimetoarriveall = std (averagetimetoarrivevalues);
semtimetoarriveall = desvpadraotimetoarriveall./ (sqrt (sujeitosOPOP));
medianatimetoarriveall = median (averagetimetoarrivevalues);

sizeandspeedanalyzis {2,14,1} = averagetimetoarrivevalues;
sizeandspeedanalyzis {3,14,1} = pValue4;
sizeandspeedanalyzis {4,14,1} = averagetimetoarriveall;
sizeandspeedanalyzis {5,14,1} = desvpadraotimetoarriveall;
sizeandspeedanalyzis {6,14,1} = sujeitosOPOP;
sizeandspeedanalyzis {7,14,1} = semtimetoarriveall;
sizeandspeedanalyzis {8,14,1} = medianatimetoarriveall;

%% Analyze for dataset OP to PA dataset
% Aritmetic average speed
sujeitosOPPA = size (dataOPPA,1)-1;% because it is counting with the label row
sujeitosloopOPPA = sujeitosOPPA + 1;

averageindspeed = dataOPPA (2:sujeitosloopOPPA, 26); %extract average speed data (harmonic)

averageindspeedvalues = zeros (sujeitosOPPA, 1);
for i=1:sujeitosOPPA;
    aisvalues = averageindspeed {i,1};
    averageindspeedvalues (i) = aisvalues;
end

if sujeitosOPPA >= 3 % each individual comes with one value for reversals
[H, pValue5, W] = swtest(averageindspeedvalues, 0.05);%null hypothesis data comes from normal distribuition; if h=1 reject null hypothesis that data comes from a normal distribuition
elseif sujeitosOPPA ==2 
    pValue5 = NaN;
elseif sujeitosOPPA ==1 
    pValue5 = NaN;
elseif sujeitosOPPA ==0
    pValue5= NaN;
end

averagespeedall = mean (averageindspeedvalues);
desvpadraoavrspeedall = std (averageindspeedvalues);
semavrspeedall = desvpadraoavrspeedall./ (sqrt (sujeitosOPPA));
medianaavrspeedall = median (averageindspeedvalues);

sizeandspeedanalyzis {2,3,1} = averageindspeedvalues;
sizeandspeedanalyzis {3,3,1} = pValue5;
sizeandspeedanalyzis {4,3,1} = averagespeedall;
sizeandspeedanalyzis {5,3,1} = desvpadraoavrspeedall;
sizeandspeedanalyzis {6,3,1} = sujeitosOPPA;
sizeandspeedanalyzis {7,3,1} = semavrspeedall;
sizeandspeedanalyzis {8,3,1} = medianaavrspeedall;

% Speed range

indspeedrange = dataOPPA (2:sujeitosloopOPPA, 25); %extracts speed range for each animal

indspeedrangevalues = zeros (sujeitosOPPA, 1);
for i=1:sujeitosOPPA;
    isrvalues = indspeedrange {i,1};
    indspeedrangevalues(i) = isrvalues;
end

if sujeitosOPPA >= 3 % each individual comes with one value for reversals
[H, pValue6, W] = swtest(indspeedrangevalues, 0.05);%null hypothesis data comes from normal distribuition; if h=1 reject null hypothesis that data comes from a normal distribuition
elseif sujeitosOPPA ==2 
    pValue6 = NaN;
elseif sujeitosOPPA ==1 
    pValue6 = NaN;
elseif sujeitosOPPA ==0
    pValue6 = NaN;
end
 
rangespeedall = mean (indspeedrangevalues);
desvpadraorangespeedall = std (indspeedrangevalues);
semrangespeedall = desvpadraorangespeedall./ (sqrt (sujeitosOPPA));
medianarangespeedall = median (indspeedrangevalues);

sizeandspeedanalyzis {2,7,1} = indspeedrangevalues;
sizeandspeedanalyzis {3,7,1} = pValue6;
sizeandspeedanalyzis {4,7,1} = rangespeedall;
sizeandspeedanalyzis {5,7,1} = desvpadraorangespeedall;
sizeandspeedanalyzis {6,7,1} = sujeitosOPPA;
sizeandspeedanalyzis {7,7,1} = semrangespeedall;
sizeandspeedanalyzis {8,7,1} = medianarangespeedall;

% Size

indsize = dataOPPA (2:sujeitosloopOPPA, 13); %extracts size for each animal

indsizevalues = zeros (sujeitosOPPA,1);
for i=1:sujeitosOPPA;
    isizevalues = indsize {i,1};
    indsizevalues(i) = isizevalues;
end

if sujeitosOPPA >= 3 % each individual comes with one value for reversals
[H, pValue7, W] = swtest(indsizevalues, 0.05);%null hypothesis data comes from normal distribuition; if h=1 reject null hypothesis that data comes from a normal distribuition
elseif sujeitosOPPA ==2 
    pValue7 = NaN;
elseif sujeitosOPPA ==1 
    pValue7 = NaN;
elseif sujeitosOPPA ==0
    pValue7 = NaN;
 end

sizeall = mean (indsizevalues);
desvpadraosizeall = std (indsizevalues);
semsizeall = desvpadraosizeall./ (sqrt (sujeitosOPPA));
medianasizeall = median (indsizevalues);

sizeandspeedanalyzis {2,11,1} = indsizevalues;
sizeandspeedanalyzis {3,11,1} = pValue7;
sizeandspeedanalyzis {4,11,1} = sizeall;
sizeandspeedanalyzis {5,11,1} = desvpadraosizeall;
sizeandspeedanalyzis {6,11,1} = sujeitosOPPA;
sizeandspeedanalyzis {7,11,1} = semsizeall;
sizeandspeedanalyzis {8,11,1} = medianasizeall;

%time to arrive
averagetimetoarrive = dataOPPA (2:sujeitosloopOPPA, 12); %extract time to arrive

averagetimetoarrivevalues = zeros (sujeitosOPPA,1);
for i=1:sujeitosOPPA;
    attavalues = averagetimetoarrive {i,1};
    averagetimetoarrivevalues(i) = attavalues;
end

if sujeitosOPPA >= 3 % each individual comes with one value for reversals
[H, pValue8, W] = swtest(averagetimetoarrivevalues, 0.05);%null hypothesis data comes from normal distribuition; if h=1 reject null hypothesis that data comes from a normal distribuition
elseif sujeitosOPPA ==2 
    pValue8 = NaN;
elseif sujeitosOPPA ==1 
    pValue8 = NaN;
elseif sujeitosOPPA ==0
    pValue8 = NaN;
 end
 
averagetimetoarriveall = mean (averagetimetoarrivevalues);
desvpadraotimetoarriveall = std (averagetimetoarrivevalues);
semtimetoarriveall = desvpadraotimetoarriveall./ (sqrt (sujeitosOPPA));
medianatimetoarriveall = median (averagetimetoarrivevalues);

sizeandspeedanalyzis {2,15,1} = averagetimetoarrivevalues;
sizeandspeedanalyzis {3,15,1} = pValue8;
sizeandspeedanalyzis {4,15,1} = averagetimetoarriveall;
sizeandspeedanalyzis {5,15,1} = desvpadraotimetoarriveall;
sizeandspeedanalyzis {6,15,1} = sujeitosOPPA;
sizeandspeedanalyzis {7,15,1} = semtimetoarriveall;
sizeandspeedanalyzis {8,15,1} = medianatimetoarriveall;

%% Analyze for dataset PA to OP dataset
% Aritmetic average speed
sujeitosPAOP = size (dataPAOP,1)-1;% because it is counting with the label row
sujeitosloopPAOP = sujeitosPAOP + 1;

averageindspeed = dataPAOP (2:sujeitosloopPAOP, 26); %extract average speed data (harmonic)

averageindspeedvalues = zeros (sujeitosPAOP, 1);
for i=1:sujeitosPAOP;
    aisvalues = averageindspeed {i,1};
    averageindspeedvalues(i) = aisvalues;
end

if sujeitosPAOP >= 3 % each individual comes with one value for reversals
[H, pValue9, W] = swtest(averageindspeedvalues, 0.05);%null hypothesis data comes from normal distribuition; if h=1 reject null hypothesis that data comes from a normal distribuition
elseif sujeitosPAOP ==2 
    pValue9 = NaN;
elseif sujeitosPAOP ==1 
    pValue9 = NaN;
elseif sujeitosPAOP ==0
    pValue9 = NaN;
 end
 
averagespeedall = mean (averageindspeedvalues);
desvpadraoavrspeedall = std (averageindspeedvalues);
semavrspeedall = desvpadraoavrspeedall./ (sqrt (sujeitosPAOP));
medianaavrspeedall = median (averageindspeedvalues);

sizeandspeedanalyzis {2,4,1} = averageindspeedvalues;
sizeandspeedanalyzis {3,4,1} = pValue9;
sizeandspeedanalyzis {4,4,1} = averagespeedall;
sizeandspeedanalyzis {5,4,1} = desvpadraoavrspeedall;
sizeandspeedanalyzis {6,4,1} = sujeitosPAOP;
sizeandspeedanalyzis {7,4,1} = semavrspeedall;
sizeandspeedanalyzis {8,4,1} = medianaavrspeedall;

% Speed range

indspeedrange = dataPAOP (2:sujeitosloopPAOP, 25); %extracts speed range for each animal

indspeedrangevalues = zeros (sujeitosPAOP,1);
for i=1:sujeitosPAOP;
    isrvalues = indspeedrange {i,1};
    indspeedrangevalues(i) = isrvalues;
end

if sujeitosPAOP >= 3 % each individual comes with one value for reversals
[H, pValue10, W] = swtest(indspeedrangevalues, 0.05);%null hypothesis data comes from normal distribuition; if h=1 reject null hypothesis that data comes from a normal distribuition
elseif sujeitosPAOP ==2 
    pValue10 = NaN;
elseif sujeitosPAOP ==1 
    pValue10 = NaN;
elseif sujeitosPAOP ==0
    pValue10 = NaN;
 end
 
rangespeedall = mean (indspeedrangevalues);
desvpadraorangespeedall = std (indspeedrangevalues);
semrangespeedall = desvpadraorangespeedall./ (sqrt (sujeitosPAOP));
medianarangespeedall = median (indspeedrangevalues);

sizeandspeedanalyzis {2,8,1} = indspeedrangevalues;
sizeandspeedanalyzis {3,8,1} = pValue10;
sizeandspeedanalyzis {4,8,1} = rangespeedall;
sizeandspeedanalyzis {5,8,1} = desvpadraorangespeedall;
sizeandspeedanalyzis {6,8,1} = sujeitosPAOP;
sizeandspeedanalyzis {7,8,1} = semrangespeedall;
sizeandspeedanalyzis {8,8,1} = medianarangespeedall;

% Size

indsize = dataPAOP (2:sujeitosloopPAOP, 13); %extracts size for each animal

indsizevalues = zeros (sujeitosPAOP,1);
for i=1:sujeitosPAOP;
    isizevalues = indsize {i,1};
    indsizevalues(i) = isizevalues;
end

if sujeitosPAOP >= 3 % each individual comes with one value for reversals
[H, pValue11, W] = swtest(indsizevalues, 0.05);%null hypothesis data comes from normal distribuition; if h=1 reject null hypothesis that data comes from a normal distribuition
elseif sujeitosPAOP ==2 
    pValue11 = NaN;
elseif sujeitosPAOP ==1 
    pValue11 = NaN;
elseif sujeitosPAOP ==0
    pValue11= NaN;
 end
 
sizeall = mean (indsizevalues);
desvpadraosizeall = std (indsizevalues);
semsizeall = desvpadraosizeall./ (sqrt (sujeitosPAOP));
medianasizeall = median (indsizevalues);

sizeandspeedanalyzis {2,12,1} = indsizevalues;
sizeandspeedanalyzis {3,12,1} = pValue11;
sizeandspeedanalyzis {4,12,1} = sizeall;
sizeandspeedanalyzis {5,12,1} = desvpadraosizeall;
sizeandspeedanalyzis {6,12,1} = sujeitosPAOP;
sizeandspeedanalyzis {7,12,1} = semsizeall;
sizeandspeedanalyzis {8,12,1} = medianasizeall;

%time to arrive
averagetimetoarrive = dataPAOP (2:sujeitosloopPAOP, 12); %extract time to arrive

averagetimetoarrivevalues = zeros (sujeitosPAOP,1);
for i=1:sujeitosPAOP;
    attavalues = averagetimetoarrive {i,1};
    averagetimetoarrivevalues(i) = attavalues;
end

if sujeitosPAOP >= 3 % each individual comes with one value for reversals
[H, pValue12, W] = swtest(averagetimetoarrivevalues, 0.05);%null hypothesis data comes from normal distribuition; if h=1 reject null hypothesis that data comes from a normal distribuition
elseif sujeitosPAOP ==2 
    pValue12 = NaN;
elseif sujeitosPAOP ==1 
    pValue12 = NaN;
elseif sujeitosPAOP ==0
    pValue12= NaN;
 end
 
averagetimetoarriveall = mean (averagetimetoarrivevalues);
desvpadraotimetoarriveall = std (averagetimetoarrivevalues);
semtimetoarriveall = desvpadraotimetoarriveall./ (sqrt (sujeitosPAOP));
medianatimetoarriveall = median (averagetimetoarrivevalues);

sizeandspeedanalyzis {2,16,1} = averagetimetoarrivevalues;
sizeandspeedanalyzis {3,16,1} = pValue12;
sizeandspeedanalyzis {4,16,1} = averagetimetoarriveall;
sizeandspeedanalyzis {5,16,1} = desvpadraotimetoarriveall;
sizeandspeedanalyzis {6,16,1} = sujeitosPAOP;
sizeandspeedanalyzis {7,16,1} = semtimetoarriveall;
sizeandspeedanalyzis {8,16,1} = medianatimetoarriveall;

%% Analyze for dataset PA to PA dataset
% Aritmetic average speed
sujeitosPAPA = size (dataPAPA,1)-1;% because it is counting with the label row
sujeitosloopPAPA = sujeitosPAPA + 1;

averageindspeed = dataPAPA (2:sujeitosloopPAPA, 26); %extract average speed data (harmonic)

averageindspeedvalues = zeros (sujeitosPAPA, 1);
for i=1:sujeitosPAPA;
    aisvalues = averageindspeed {i,1};
    averageindspeedvalues(i) = aisvalues;
end

if sujeitosPAPA >= 3 % each individual comes with one value for reversals
[H, pValue13, W] = swtest(averageindspeedvalues, 0.05);%null hypothesis data comes from normal distribuition; if h=1 reject null hypothesis that data comes from a normal distribuition
elseif sujeitosPAPA ==2 
    pValue13 = NaN;
elseif sujeitosPAPA ==1 
    pValue13 = NaN;
elseif sujeitosPAPA ==0
    pValue13= NaN;
 end
 
averagespeedall = mean (averageindspeedvalues);
desvpadraoavrspeedall = std (averageindspeedvalues);
semavrspeedall = desvpadraoavrspeedall./ (sqrt (sujeitosPAPA));
medianaavrspeedall = median (averageindspeedvalues);

sizeandspeedanalyzis {2,5,1} = averageindspeedvalues;
sizeandspeedanalyzis {3,5,1} = pValue13;
sizeandspeedanalyzis {4,5,1} = averagespeedall;
sizeandspeedanalyzis {5,5,1} = desvpadraoavrspeedall;
sizeandspeedanalyzis {6,5,1} = sujeitosPAPA;
sizeandspeedanalyzis {7,5,1} = semavrspeedall;
sizeandspeedanalyzis {8,5,1} = medianaavrspeedall;

% Speed range

indspeedrange = dataPAPA (2:sujeitosloopPAPA, 25); %extracts speed range for each animal

indspeedrangevalues = zeros (sujeitosPAPA, 1);
for i=1:sujeitosPAPA;
    isrvalues = indspeedrange {i,1};
    indspeedrangevalues(i) = isrvalues;
end

if sujeitosPAPA >= 3 % each individual comes with one value for reversals
[H, pValue14, W] = swtest(indspeedrangevalues, 0.05);%null hypothesis data comes from normal distribuition; if h=1 reject null hypothesis that data comes from a normal distribuition
elseif sujeitosPAPA ==2 
    pValue14 = NaN;
elseif sujeitosPAPA ==1 
    pValue14 = NaN;
elseif sujeitosPAPA ==0
    pValue14= NaN;
end
 
rangespeedall = mean (indspeedrangevalues);
desvpadraorangespeedall = std (indspeedrangevalues);
semrangespeedall = desvpadraorangespeedall./ (sqrt (sujeitosPAPA));
medianarangespeedall = median (indspeedrangevalues);

sizeandspeedanalyzis {2,9,1} = indspeedrangevalues;
sizeandspeedanalyzis {3,9,1} = pValue14;
sizeandspeedanalyzis {4,9,1} = rangespeedall;
sizeandspeedanalyzis {5,9,1} = desvpadraorangespeedall;
sizeandspeedanalyzis {6,9,1} = sujeitosPAPA;
sizeandspeedanalyzis {7,9,1} = semrangespeedall;
sizeandspeedanalyzis {8,9,1} = medianarangespeedall;

% Size

indsize = dataPAPA (2:sujeitosloopPAPA, 13); %extracts size for each animal

indsizevalues = zeros (sujeitosPAPA,1);
for i=1:sujeitosPAPA;
    isizevalues = indsize {i,1};
    indsizevalues(i) = isizevalues;
end

if sujeitosPAPA >= 3 % each individual comes with one value for reversals
[H, pValue15, W] = swtest(indsizevalues, 0.05);%null hypothesis data comes from normal distribuition; if h=1 reject null hypothesis that data comes from a normal distribuition
elseif sujeitosPAPA ==2 
    pValue15 = NaN;
elseif sujeitosPAPA ==1 
    pValue15 = NaN;
elseif sujeitosPAPA ==0
    pValue15= NaN;
end
 
sizeall = mean (indsizevalues);
desvpadraosizeall = std (indsizevalues);
semsizeall = desvpadraosizeall./ (sqrt (sujeitosPAPA));
medianasizeall = median (indsizevalues);

sizeandspeedanalyzis {2,13,1} = indsizevalues;
sizeandspeedanalyzis {3,13,1} = pValue15;
sizeandspeedanalyzis {4,13,1} = sizeall;
sizeandspeedanalyzis {5,13,1} = desvpadraosizeall;
sizeandspeedanalyzis {6,13,1} = sujeitosPAPA;
sizeandspeedanalyzis {7,13,1} = semsizeall;
sizeandspeedanalyzis {8,13,1} = medianasizeall;

%time to arrive
averagetimetoarrive = dataPAPA (2:sujeitosloopPAPA, 12); %extract time to arrive

averagetimetoarrivevalues = zeros (sujeitosPAPA, 1);
for i=1:sujeitosPAPA;
    attavalues = averagetimetoarrive {i,1};
    averagetimetoarrivevalues(i) = attavalues;
end

if sujeitosPAPA >= 3 % each individual comes with one value for reversals
[H, pValue16, W] = swtest(averagetimetoarrivevalues, 0.05);%null hypothesis data comes from normal distribuition; if h=1 reject null hypothesis that data comes from a normal distribuition
elseif sujeitosPAPA ==2 
    pValue16 = NaN;
elseif sujeitosPAPA ==1 
    pValue16 = NaN;
elseif sujeitosPAPA ==0
    pValue16= NaN;
end
 
averagetimetoarriveall = mean (averagetimetoarrivevalues);
desvpadraotimetoarriveall = std (averagetimetoarrivevalues);
semtimetoarriveall = desvpadraotimetoarriveall./ (sqrt (sujeitosPAPA));
medianatimetoarriveall = median (averagetimetoarrivevalues);

sizeandspeedanalyzis {2,17,1} = averagetimetoarrivevalues;
sizeandspeedanalyzis {3,17,1} = pValue16;
sizeandspeedanalyzis {4,17,1} = averagetimetoarriveall;
sizeandspeedanalyzis {5,17,1} = desvpadraotimetoarriveall;
sizeandspeedanalyzis {6,17,1} = sujeitosPAPA;
sizeandspeedanalyzis {7,17,1} = semtimetoarriveall;
sizeandspeedanalyzis {8,17,1} = medianatimetoarriveall;

%% Create box plots for Average Speed
avgindspeedOPOP = sizeandspeedanalyzis (2,2,1);
avgindspeedOPOPvalues = avgindspeedOPOP {1,1};

avgindspeedOPPA = sizeandspeedanalyzis (2,3,1);
avgindspeedOPPAvalues = avgindspeedOPPA {1,1};

avgindspeedPAOP = sizeandspeedanalyzis (2,4,1);
avgindspeedPAOPvalues = avgindspeedPAOP {1,1};

avgindspeedPAPA = sizeandspeedanalyzis (2,5,1);
avgindspeedPAPAvalues = avgindspeedPAPA {1,1};

matrix = NaN (8,4);% create a matrix in the begining full of NaN to guarantee that the matrix have 
% all the same dimensions and can be concatenated

matrix (1:sujeitosOPOP, 1) = avgindspeedOPOPvalues; %chande dimesnions
matrix (1:sujeitosOPPA, 2) = avgindspeedOPPAvalues; %change dimensions 
matrix (1:sujeitosPAOP, 3) = avgindspeedPAOPvalues; %change dimensions
matrix (1:sujeitosPAPA, 4) = avgindspeedPAPAvalues; %change dimensions


boxplot (matrix, 'Labels',{'OP to OP','OP to PA', 'PA to OP', 'PA to PA'});
ylim ([0,600]);
title ('RRF3_Exp11_N2 Average speed');
ylabel ('micro/sec');

%% Create box plots for speed range
avgindspeedrangeOPOP = sizeandspeedanalyzis (2,6,1);
avgindspeedrangeOPOPvalues = avgindspeedrangeOPOP {1,1};

avgindspeedrangeOPPA = sizeandspeedanalyzis (2,7,1);
avgindspeedrangeOPPAvalues = avgindspeedrangeOPPA {1,1};

avgindspeedrangePAOP = sizeandspeedanalyzis (2,8,1);
avgindspeedrangePAOPvalues = avgindspeedrangePAOP {1,1};

avgindspeedrangePAPA = sizeandspeedanalyzis (2,9,1);
avgindspeedrangePAPAvalues = avgindspeedrangePAPA {1,1};

matrix = NaN (8,4);

matrix (1:sujeitosOPOP, 1) = avgindspeedrangeOPOPvalues; %chande dimesnions
matrix (1:sujeitosOPPA, 2) = avgindspeedrangeOPPAvalues; %change dimensions 
matrix (1:sujeitosPAOP, 3) = avgindspeedrangePAOPvalues; %change dimensions
matrix (1:sujeitosPAPA, 4) = avgindspeedrangePAPAvalues; %change dimensions

figure
boxplot (matrix, 'Labels',{'OP to OP','OP to PA', 'PA to OP', 'PA to PA'});
ylim ([0,1200]);
title ('RRF3_Exp11_N2 Speed range');
ylabel ('micro/sec');

%% Create box plots for size
avgindsizeOPOP = sizeandspeedanalyzis (2,10,1);
avgindsizeOPOPvalues = avgindsizeOPOP {1,1};

avgindsizeOPPA = sizeandspeedanalyzis (2,11,1);
avgindsizeOPPAvalues = avgindsizeOPPA {1,1};

avgindsizePAOP = sizeandspeedanalyzis (2,12,1);
avgindsizePAOPvalues = avgindsizePAOP {1,1};

avgindsizePAPA = sizeandspeedanalyzis (2,13,1);
avgindsizePAPAvalues = avgindsizePAPA {1,1};

matrix = NaN (8,4);

matrix (1:sujeitosOPOP, 1) = avgindsizeOPOPvalues; 
matrix (1:sujeitosOPPA, 2) = avgindsizeOPPAvalues;  
matrix (1:sujeitosPAOP, 3) = avgindsizePAOPvalues; 
matrix (1:sujeitosPAPA, 4) = avgindsizePAPAvalues; 

figure
boxplot (matrix, 'Labels',{'OP to OP','OP to PA', 'PA to OP', 'PA to PA'});
ylim ([750,1300]);
title ('RRF3_Exp11_N2 size');
ylabel ('micro');

%% Create a plot for size of OP and PA worms separately
allOP = sujeitosOPOP + sujeitosOPPA;
allPA = sujeitosPAOP + sujeitosPAPA;

alltogetherOP = [avgindsizeOPOPvalues;avgindsizeOPPAvalues]; 
alltogetherPA = [avgindsizePAOPvalues;avgindsizePAPAvalues];

matrix = NaN (16,2);

matrix (1:allOP, 1) = alltogetherOP; 
matrix (1:allPA, 2) = alltogetherPA;  


figure
boxplot (matrix, 'Labels',{'OPworms','PAworms'});
ylim ([750,1300]);
title ('RRF3_Exp11_N2 size OP vs PA');
ylabel ('micro');



%% Create box plots for time to arrive
avgindttaOPOP = sizeandspeedanalyzis (2,14,1);
avgindttaOPOPvalues = avgindttaOPOP {1,1};

avgindttaOPPA = sizeandspeedanalyzis (2,15,1);
avgindttaOPPAvalues = avgindttaOPPA {1,1};

avgindttaPAOP = sizeandspeedanalyzis (2,16,1);
avgindttaPAOPvalues = avgindttaPAOP {1,1};

avgindttaPAPA = sizeandspeedanalyzis (2,17,1);
avgindttaPAPAvalues = avgindttaPAPA {1,1};

matrix = NaN (8,4);

matrix (1:sujeitosOPOP, 1) = avgindttaOPOPvalues; 
matrix (1:sujeitosOPPA, 2) = avgindttaOPPAvalues;  
matrix (1:sujeitosPAOP, 3) = avgindttaPAOPvalues;
matrix (1:sujeitosPAPA, 4) = avgindttaPAPAvalues; 

figure
boxplot (matrix, 'Labels',{'OP to OP','OP to PA', 'PA to OP', 'PA to PA'});
ylim ([0,600]);
title ('RRF3_Exp11_N2 timetoarrive');
ylabel ('sec');

RRF3_Exp30_ZC2834_speedanalyzisall = sizeandspeedanalyzis;

